package com.csun.cmny.provider.service.impl;

import com.csun.cmny.core.support.BaseService;
import com.csun.cmny.provider.dao.DmcPatrolDataMapper;
import com.csun.cmny.provider.model.domain.DmcPatrolData;
import com.csun.cmny.provider.service.DmcPatrolDataService;
import com.csun.cmny.util.PublicUtil;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;

/**
 * @Auther: chisj chisj@foxmal.com
 * @Date: 2021/7/29 9:49
 * @Description: 巡更棒数据接口实现类
 */
@Service
public class DmcPatrolDataServiceImpl extends BaseService<DmcPatrolData>
        implements DmcPatrolDataService {

    @Resource
    private DmcPatrolDataMapper dmcPatrolDataMapper;

    /**
     * 保存或者更新巡更棒数据
     *
     * @param dmcPatrolData the dmc patrol data
     *
     * @return  the int
     */
    @Override
    public Integer saveOrUpdate(DmcPatrolData dmcPatrolData) {

        DmcPatrolData record = dmcPatrolDataMapper.selectByPrimaryKey(dmcPatrolData.getDeviceId());
        if (PublicUtil.isEmpty(record)) {
            return dmcPatrolDataMapper.insertSelective(dmcPatrolData);
        } else {
            dmcPatrolData.setUpdateTime(new Date());
            return dmcPatrolDataMapper.updateByPrimaryKeySelective(dmcPatrolData);
        }
    }
}
